package com.example.weather.logic.network

import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

object ServiceCreator {
    private const val BASE_URL = "https://api.caiyunapp.com/"
    private val retrofit = Retrofit.Builder()
        .baseUrl(BASE_URL)
        .addConverterFactory(GsonConverterFactory.create())//解析数据时使用的数据转换库
        .build()

    fun <T> create(serviceClass: Class<T>): T = retrofit.create(serviceClass)
    inline fun <reified T> create(): T = create(T::class.java)//泛型实化 inline 内联函数 reified表明实化
}
/*原来的写法：
private val retrofit = Retrofit.Builder()
    .baseUrl(BASE_URL)
    .addConverterFactory(GsonConverterFactory.create())//解析数据时使用的数据转换库
    .build()
val placeService = retrofit.create(PlaceService::class.java)
每次都需要调用一次，使用object改写后添加fun <T> ...
val placeService = ServiceCreator.create(PlaceService::class.java)
使用inline 关键字修饰的语句是泛型实化添加后即可：
val placeService = ServiceCreator.create<PlaceService>()
*/